package comhh.orderservice.controller;

import comhh.orderservice.entity.Order;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * url 传参 /doOrder/热干面/add/油条/aaa
 * get 传递一个参数
 * get 传递多个参数
 * post 传递一个对象
 * post 传递一个对象 + 一个基本参数
 * post 两个对象
 */
@RestController
public class ParamController {

    @GetMapping("/testUrl/{name}/and/{age}")
    public String testUrl(@PathVariable("name") String name, @PathVariable("age") Integer age) {
        System.out.println(name + age);
        return "ok";
    }

    /**
     * @RequestParam(required = false) 参数可有可无
     * @param name
     * @return
     */
    @GetMapping("/oneParam")
    public String oneParam(@RequestParam(required = false) String name) {
        System.out.println("name = " + name);
        return "ok";
    }

    @GetMapping("/twoParam")
    public String twoParam(@RequestParam(required = false) String name, @RequestParam(required = false) Integer age) {
        System.out.println("name = " + name);
        System.out.println("age = " + age);
        return "ok";
    }

    @PostMapping("/oneObj")
    public String oneObj(@RequestBody Order order) {
        System.out.println("order = " + order);
        return "ok";
    }

    @PostMapping("/oneObjOneParam")
    public String oneObjOneParam(@RequestBody Order order, @RequestParam("name") String name) {
        System.out.println("order = " + order);
        System.out.println("name = " + name);
        return "ok";
    }

    @GetMapping("/testTime")
    public String testTime(@RequestParam Date date) {
        System.out.println("date = " + date);
        return "ok";
    }
}
